/* jshint esversion: 8 */
import * as types from '@/store/types.js';
import { postLoginByWeixin } from '@/api/user';

export default {
  state: {
    LoginByWeixin: {},
  },
  
  getters: {
    /*** 返回 用户登录 数据 ***/
    [types.GLoginByWeixin](state) {
      return state.LoginByWeixin;
    },
  },

  actions: {
    /*** 获取 用户登录 数据 ***/
    [types.ALoginByWeixin](ctx, query) {
      return new Promise((resolve, reject) => {
        postLoginByWeixin(query).then(({data}) => {
          ctx.commit(types.MLoginByWeixin, data);
          resolve();
        }).catch(error => {
          ctx.commit(types.MLoginByWeixin, {});
          reject(error);
        });
      });
    },
  },

  mutations: {
    /*** 填充 用户登录 数据 ***/
    [types.MLoginByWeixin](state, access) {
      state.LoginByWeixin = access;
    },
  }
};